# ///////////////////////////////////////////////////////////////
#
# BY: WANDERSON M.PIMENTA
# PROJECT MADE WITH: Qt Designer and PySide6
# V: 1.0.0
#
# This project can be used freely for all uses, as long as they maintain the
# respective credits only in the Python scripts, any information in the visual
# interface (GUI) can be modified without any implication.
#
# There are limitations on Qt licenses if you want to use your products
# commercially, I recommend reading them on the official website:
# https://doc.qt.io/qtforpython/licenses.html
#
# 这个项目可以被所有用户自由使用，只要他们只在Python脚本中保留各自的原作者信息，
# 可视界面(GUI)中的任何信息都可以被修改而不需要任何暗示。
# 如果你想在商业上使用你的产品，Qt许可证是有限制的，我建议你在官方网站上阅读它们
# ///////////////////////////////////////////////////////////////


# IMPORT QT CORE
from qt_core import *

# IMPORT PAGES
from gui.pages.ui_pages import Ui_application_pages

# IMPORT CUSTOM WIDGETS
from gui.widgets.py_push_button import PyPushButton


# MAIN WINDOW
class UI_MainWindow(object):
    def setup_ui(self, parent):
        '''parent: 一般由 main.py文件中MainWindow类的实例self变量作为父类，目的是UI_MainWindow实例做mai文件中的UI界面。
            通常，在main.py，这样调用setup_ui方法
                    # SETUP MAIN WINDOW
                    self.ui = UI_MainWindow()
                    self.ui.setup_ui(self)
        '''
        if not parent.objectName():  # 此判断，经测试，一定会进入
            parent.setObjectName("MainWindow")  # TODO(wangjh-xm): 暂时不清楚setObjectName的作用效果。
            # print('test')

        # SET INITIAL PARAMETERS
        # ///////////////////////////////////////////////////////////////
        parent.resize(1200, 720)  # 重新设启动时的界面大小
        parent.setMinimumSize(960, 540)  # 设置手动调整的最小尺寸

        # CREATE CENTRAL WIDGET (创建中央画面)
        self.central_frame = QFrame()

        # CREATE MAIN LAYOUT (创建主布局为水平布局：左边菜单栏 + 右边内容栏)
        self.main_layout = QHBoxLayout(self.central_frame)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.setSpacing(0)

        # region 左菜单栏汇总
        # LEFT MANU (左菜单栏)
        self.left_menu = QFrame()
        self.left_menu.setStyleSheet("background-color: #44475a")
        self.left_menu.setMaximumWidth(50)
        self.left_menu.setMinimumWidth(50)

        # LEFT MENU LAYOUT (左菜单栏 垂直布局)
        self.left_menu_layout = QVBoxLayout(self.left_menu)
        self.left_menu_layout.setContentsMargins(0, 0, 0, 0)
        self.left_menu_layout.setSpacing(0)

        # region 左菜单 顶部画面菜单（负责增加切换中间主页的索引按钮）
        # TOP FRAME MENU
        self.left_menu_top_frame = QFrame()
        self.left_menu_top_frame.setMinimumHeight(50)
        self.left_menu_top_frame.setObjectName("left_menu_top_frame")
        self.left_menu_top_frame.setStyleSheet("#left_menu_top_frame { background-color: red; }")

        # TOP FRAME LAYOUT
        self.left_menu_top_frame_layout = QVBoxLayout(self.left_menu_top_frame)
        self.left_menu_top_frame_layout.setContentsMargins(0, 0, 0, 0)
        self.left_menu_top_frame_layout.setSpacing(0)

        # TOP BTNS
        self.btn_toggle = PyPushButton(text="隐藏菜单", icon_path="icon_menu.svg")
        self.btn_1 = PyPushButton(text="主页", is_active=True, icon_path="icon_home.svg")
        self.btn_2 = PyPushButton(text="页2", icon_path="icon_widgets.svg")

        # ADD TO TOP FRAME LAYOUT
        self.left_menu_top_frame_layout.addWidget(self.btn_toggle)
        self.left_menu_top_frame_layout.addWidget(self.btn_1)
        self.left_menu_top_frame_layout.addWidget(self.btn_2)
        # endregion

        # MENU SPACER
        self.left_menu_spacer = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding)

        # region 左菜单 底部画面菜单（负责增加切换中间主页的索引按钮）
        # BOTTOM FRAME MENU
        self.left_menu_bottom_frame = QFrame()
        self.left_menu_bottom_frame.setMinimumHeight(50)
        self.left_menu_bottom_frame.setObjectName("left_menu_bottom_frame")
        self.left_menu_bottom_frame.setStyleSheet("#left_menu_bottom_frame { background-color: red; }")

        # BOTTOM FRAME LAYOUT
        self.left_menu_bottom_frame_layout = QVBoxLayout(self.left_menu_bottom_frame)
        self.left_menu_bottom_frame_layout.setContentsMargins(0, 0, 0, 0)
        self.left_menu_bottom_frame_layout.setSpacing(0)

        # BOTTOM BTNS
        self.btn_settings = PyPushButton(text="设置", icon_path="icon_settings.svg")

        # ADD TO BOTTOM FRAME LAYOUT
        self.left_menu_bottom_frame_layout.addWidget(self.btn_settings)
        # endregion

        # LEBEL VERSION
        self.left_menu_label_version = QLabel("V1.0.0")
        self.left_menu_label_version.setAlignment(Qt.AlignCenter)
        self.left_menu_label_version.setMinimumHeight(30)
        self.left_menu_label_version.setMaximumHeight(30)
        self.left_menu_label_version.setStyleSheet("color: #c3ccdf")

        # ADD TO LAYOUT
        self.left_menu_layout.addWidget(self.left_menu_top_frame)
        self.left_menu_layout.addItem(self.left_menu_spacer)
        self.left_menu_layout.addWidget(self.left_menu_bottom_frame)
        self.left_menu_layout.addWidget(self.left_menu_label_version)

        # endregion

        # region 内容栏汇总
        # CONTENT (右侧内容栏)
        self.content = QFrame()
        self.content.setStyleSheet("background-color: #282a36")

        # CONTENT LAYOUT (内容栏内部布局为垂直布局：顶部bar + 中间页面 + 底部bar)
        self.content_layout = QVBoxLayout(self.content)
        self.content_layout.setContentsMargins(0, 0, 0, 0)
        self.content_layout.setSpacing(0)

        # region 内容(content)页面中的 顶部栏(top bar)
        # TOP BAR
        self.top_bar = QFrame()
        self.top_bar.setMinimumHeight(30)
        self.top_bar.setMaximumHeight(30)
        self.top_bar.setStyleSheet("background-color: #21232d; color: #6272a4")
        self.top_bar_layout = QHBoxLayout(self.top_bar)
        self.top_bar_layout.setContentsMargins(10, 0, 10, 0)

        # TOP LEFT LABEL
        self.top_label_left = QLabel("这是我的第一个PySide6应用程序")

        # TOP SPACER
        self.top_spacer = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        # TOP REGHT LABEL
        self.top_label_right = QLabel("| 主页")
        self.top_label_right.setStyleSheet("font:700 9pt 'Segoe UI'")

        # ADD TO TOP BAR LAYOUT
        self.top_bar_layout.addWidget(self.top_label_left)
        self.top_bar_layout.addItem(self.top_spacer)  # 注意 spacer 是Item,所以用addItem
        self.top_bar_layout.addWidget(self.top_label_right)
        # endregion

        # region 内容(content)页面中的 应用页面(pages)
        # Application pages
        self.pages = QStackedWidget()
        self.pages.setStyleSheet("font-size: 12pt; color: #f8f8f2;")
        self.ui_pages = Ui_application_pages()  # 实例化 ui设计文件中的堆栈窗口类
        self.ui_pages.setupUi(self.pages)  # 将self.pages作为setupUi的实例参数application_pages
        self.pages.setCurrentWidget(self.ui_pages.page_1)  # 设置当前显示页面为page_1
        # endregion

        # region 内容(content)页面中的 底部栏(bottom bar)
        # BUTTOM BAR
        self.bottom_bar = QFrame()
        self.bottom_bar.setMinimumHeight(30)
        self.bottom_bar.setMaximumHeight(30)
        self.bottom_bar.setStyleSheet("background-color: #21232d; color: #6272a4")
        self.bottom_bar_layout = QHBoxLayout(self.bottom_bar)
        self.bottom_bar_layout.setContentsMargins(10, 0, 10, 0)

        # BOTTOM LEFT LABEL
        self.bottom_label_left = QLabel("作者: Wanderson M. Pimenta")

        # BOTTOM SPACER
        self.bottom_spacer = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        # BOTTOM REGHT LABEL
        self.bottom_label_right = QLabel("© 2021.11")
        self.bottom_label_right.setStyleSheet("font:700 9pt 'Segoe UI'")

        # ADD TO BOTTOM BAR LAYOUT
        self.bottom_bar_layout.addWidget(self.bottom_label_left)
        self.bottom_bar_layout.addItem(self.bottom_spacer)  # 注意 spacer 是Item,所以用addItem
        self.bottom_bar_layout.addWidget(self.bottom_label_right)
        # endregion

        # region 将内容(content)页面中的 3个大控件 top-bar + pages + bottom-bar 添加到内容页面的垂直布局中
        # ADD TO CONTENT LAYOUT
        self.content_layout.addWidget(self.top_bar)
        self.content_layout.addWidget(self.pages)
        self.content_layout.addWidget(self.bottom_bar)
        # endregion
        # endregion

        # region 将主画面中的 2个大控件 menu + content 添加到主页面的水平布局中
        # ADD WIDGETS TO APP
        self.main_layout.addWidget(self.left_menu)
        self.main_layout.addWidget(self.content)
        # endregion

        # SET CENTRAL (设置父类的中央画面为子类self的中央画面)
        parent.setCentralWidget(self.central_frame)
